package com.ym.b2b.product.dao.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import com.ym.b2b.commons.dao.BaseDao;
import com.ym.b2b.product.dao.EmBPromoActivityDAO;
import com.ym.b2b.product.sqlbean.EmBPromoActivity;
import com.zc.commons.base.Page;

@Repository
public class EmBPromoActivityDAOImpl<T> extends BaseDao<T> implements EmBPromoActivityDAO {

    public Long searchPageEmBPromoActivityNum(EmBPromoActivity embpromoactivity) throws DataAccessException {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("map", embpromoactivity);
        return (Long) listNum("EM_B_PROMO_ACTIVITY.searchPageEmBPromoActivityNum", map);
    }

    public void searchPageEmBPromoActivity(EmBPromoActivity embpromoactivity, Page<EmBPromoActivity> page)
                                                                                                          throws DataAccessException {
        page.setTotalRow(searchPageEmBPromoActivityNum(embpromoactivity));
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("map", embpromoactivity);
        map.put("startrow", page.getStartRow());
        map.put("pagesize", page.getPageSize());
        map.put("pageable", page.getPageable());
        page.setRows(list("EM_B_PROMO_ACTIVITY.searchPageEmBPromoActivity", map));
    }

    public void insertEmBPromoActivity(EmBPromoActivity record) throws DataAccessException {
        insert("EM_B_PROMO_ACTIVITY.insertEmBPromoActivity", record);
    }

    public int updateEmBPromoActivity(EmBPromoActivity record) throws DataAccessException {
        int rows = update("EM_B_PROMO_ACTIVITY.updateEmBPromoActivity", record);
        return rows;
    }

    public EmBPromoActivity searchEmBPromoActivity(Long activityId) throws DataAccessException {
        EmBPromoActivity key = new EmBPromoActivity();
        key.setActivityId(activityId);
        EmBPromoActivity record = (EmBPromoActivity) find("EM_B_PROMO_ACTIVITY.searchEmBPromoActivity", key);
        return record;
    }

    public int deleteEmBPromoActivity(Long activityId) throws DataAccessException {
        EmBPromoActivity key = new EmBPromoActivity();
        key.setActivityId(activityId);
        int rows = delete("EM_B_PROMO_ACTIVITY.deleteEmBPromoActivity", key);
        return rows;
    }
}
